package com.atguigu.hash;

import java.util.Objects;

public class Student {
    private int grade;
    private int cls;
    private String firstName;
    private String lastName;

    public Student(int grade, int cls, String firstName, String lastName) {
        this.grade = grade;
        this.cls = cls;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @Override
    public boolean equals(Object o){
        if(this==o){
            return true;
        }
        if(o==null){
            return false;
        }
        if(getClass()!=o.getClass()){
            return false;
        }
        Student another=(Student)o;
        return this.grade==another.grade&&this.cls==another.cls&&
                this.firstName.toLowerCase().equals(another.firstName.toLowerCase())&&
                this.lastName.toLowerCase().equals(another.lastName.toLowerCase());
    }

    @Override
    public int hashCode() {
        int B = 31;
        int hash = 0;
        hash = hash * B + grade;
        hash = hash * B + cls;
        hash = hash * B + firstName.toLowerCase().hashCode();
        hash = hash * B + lastName.toLowerCase().hashCode();
        return hash;
    }

    public static void main(String[] args) {
        Student student = new Student(1, 1, "Lucy", "Alia");
        Student student1=new Student(1,2,"Lucy","Alia");
        System.out.println(student.equals(student1));
        System.out.println(student.hashCode());
        System.out.println(student1.hashCode());
    }
}
